package com.ganbo.thread.singleton;

/**
 * Created by gan on 2020/5/21 22:31.
 */
public class StaticInnerClassDemo {

    public static StaticInnerClassDemo instance;

    private StaticInnerClassDemo() {
    }

    //静态内部类只有在使用使用到的时候才加载
    private static class InnerClass {
        private static StaticInnerClassDemo instance = new StaticInnerClassDemo();

        static {
            System.out.println("instance=====>" + instance);
        }
    }

    public static StaticInnerClassDemo getInstace() {
        return InnerClass.instance; //调用这里的getInstance方法返回使用到InnerClass，这个时候就加载内部类
    }


    public static void main(String[] args) {
        System.out.println(StaticInnerClassDemo.class.getName());
        System.out.println(StaticInnerClassDemo.getInstace().hashCode());
    }
}
